//
//  BVTimeCell.m
//  BuyVegetables1
//
//  Created by 叶思超 on 15/10/28.
//  Copyright (c) 2015年 叶思超. All rights reserved.
//

#import "BVTimeCell.h"
#import "BVTime.h"
#import "BVDurationTime.h"
#import "NSString+Extension.h"
#import "UIView+Extension.h"

@interface BVTimeCell ()
/**
 *  日期
 */
@property (nonatomic, strong) UILabel *dateLabel;
/**
 *  时间
 */
@property (nonatomic, strong) UILabel *timeLabel;
/**
 *  分割线
 */
@property (nonatomic, strong) UIView *separatorLine;
@end

@implementation BVTimeCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *CellID = @"Time";
    
    BVTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    
    if (cell == nil) {
        cell = [[BVTimeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        // 日期
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.dateLabel];
        
        // 时间
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.timeLabel];
        
        // 分割线
        self.separatorLine = [[UIView alloc] init];
        self.separatorLine.backgroundColor = [UIColor blackColor];
        self.separatorLine.alpha = 0.15;
        [self.contentView addSubview:self.separatorLine];
    }
    return self;
}

- (void)setTime:(BVDurationTime *)time {
    _time = time;
    
//    // 日期
//    CGFloat dateW = [NSString sizeWithText:time.current_date font:[UIFont systemFontOfSize:15]].width;
//    self.dateLabel.frame = CGRectMake(10, 0, dateW, self.height);
//    self.dateLabel.text = time.current_date;
    
    // 时间
    NSString *timeStr = [NSString stringWithFormat:@"%@ - %@", time.starttime, time.endtime];
    CGFloat timeW = [NSString sizeWithText:timeStr font:[UIFont systemFontOfSize:15]].width;
    self.timeLabel.frame = CGRectMake(10, 0, timeW, self.height);
    self.timeLabel.text = timeStr;
    
    // 分割线
    self.separatorLine.frame= CGRectMake(0, self.height, self.width, 0.8);
}

@end
